//
//  Lab_txtViewCell.m
//  KuWoCan
//
//  Created by hwd on 17/3/16.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "LabTxtViewCell.h"

@interface LabTxtViewCell ()

@end

@implementation LabTxtViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    _topLab = [UILabel new];
    _topLab.textColor = KwBlueColor;
    _topLab.font = [UIFont systemFontOfSize:15.0];
    _topLab.textAlignment = NSTextAlignmentLeft;
    _topLab.text = _constStr;
    [self addSubview:_topLab];
    [_topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.top.equalTo(@20);
        make.height.equalTo(@15);
    }];
    
    _txtView = [[UITextView alloc] init];
    _txtView.delegate = self;
    _txtView.backgroundColor = KwGaryColor;
    _txtView.text = _txtStr;
    _txtView.font = KwFont(14);
    _txtView.textColor = [UIColor colorWithHexString:@"55aee9"];
    [self addSubview:_txtView];
    [_txtView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topLab.mas_left);
        make.right.equalTo(@-20);
        make.top.equalTo(_topLab.mas_bottom).offset(20);
        make.height.equalTo(@150);
        make.bottom.equalTo(@-15);
    }];

    // _placeholderLabel
    // same font
    if ([UIDevice currentDevice].systemVersion.integerValue>=8.3) {
        UILabel *placeHolderLabel = [[UILabel alloc] init];
        placeHolderLabel.text = @"200ML营养多";
        placeHolderLabel.numberOfLines = 0;
        placeHolderLabel.textColor = [UIColor lightGrayColor];
        [placeHolderLabel sizeToFit];
        placeHolderLabel.font =KwFont(14);
        [_txtView addSubview:placeHolderLabel];
        [_txtView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    }
}

- (void)setConstStr:(NSString *)constStr
{
    _topLab.text = constStr;
}

- (void)setTxtStr:(NSString *)txtStr
{
    _txtView.text = txtStr;
}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    if (_block)
    {
        self.block(textView.text);
    }
    return YES;
}

-(BOOL)textViewShouldReturn:(UITextView *)textView
{
    [textView resignFirstResponder];
    return YES;
}

@end
